/*
 * Copyright (c) 2015 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShEquipmentProducerDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShEquipmentProducerService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShEquipmentProducer;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShEquipmentProducerService 实现类
 * @author KongXiangyu
 * @since 2015-09-07
 */
@Service("shEquipmentProducerService")
public class ShEquipmentProducerServiceImpl extends BaseServiceImpl<ShEquipmentProducer, Long> implements ShEquipmentProducerService {

    @Resource
    private ShEquipmentProducerDao shEquipmentProducerDao;

    public BaseDao<ShEquipmentProducer, Long> getDao() {
        return shEquipmentProducerDao;
    }

 

	
	/**
	 * 查询供应商信息列表--分页
	 * @param deviceSupplier
	 * @param page
	 * @return
	 */
    @Override
    public DataGrid queryShDeviceSupplierPage(ShEquipmentProducer equipmentProducer, PageHelper page) {
		DataGrid dataGrid = new DataGrid();
		
		ShEquipmentProducer  shEquipmentProducer= new ShEquipmentProducer();
        if (!StringUtils.isBlank(page.getSort())) {
        	shEquipmentProducer.setOrderField(page.getSort());
        }
        if (!StringUtils.isBlank(page.getOrder())) {
        	shEquipmentProducer.setOrderFieldType(page.getOrder());
        }
        if (!StringUtils.isBlank(equipmentProducer.getName())) {		//供应商名称
        	//shEquipmentProducer.addQueryData("name", equipmentProducer.getName());
        	shEquipmentProducer.setName(equipmentProducer.getName());
        }
        /* if (null != queryDeviceSupplier.getDevPersonName()) {					//联系人名称
        	queryDeviceSupplier.addQueryData("devPersonName", queryDeviceSupplier.getDevPersonName());
        }
        if (StringUtils.isNotBlank(queryDeviceSupplier.getDevPersonPhone())) {	//联系人电话
        	queryDeviceSupplier.addQueryData("devPersonPhone", queryDeviceSupplier.getDevPersonPhone());
        }
        if (null != queryDeviceSupplier.getDevPersonAdderss()) {				//联系人地址
        	queryDeviceSupplier.addQueryData("devPersonAdderss", queryDeviceSupplier.getDevPersonAdderss());
        }
        if (null != queryDeviceSupplier.getDevHezuoTime()) {					//合作时间
        	queryDeviceSupplier.addQueryData("devHezuoTime", queryDeviceSupplier.getDevHezuoTime());
        }
        if (null != queryDeviceSupplier.getCreateTime()) {						//创建时间
        	queryDeviceSupplier.addQueryData("createTime", queryDeviceSupplier.getCreateTime());
        }
        if (null != queryDeviceSupplier.getUpdateTime()) {						//更新时间
        	queryDeviceSupplier.addQueryData("updateTime", queryDeviceSupplier.getUpdateTime());
        }*/
        	
        //
        long totalCount = shEquipmentProducerDao.queryShEquipmentProducerCount(shEquipmentProducer);
        dataGrid.setTotal(totalCount);
        int startIndex = (page.getPage() - 1) * page.getRows();
        int endIndex = page.getPage() * page.getRows();
        if (totalCount > 0 && totalCount > startIndex) {
        	shEquipmentProducer.setStartIndex(startIndex);
        	shEquipmentProducer.setEndIndex(endIndex);
            List<ShEquipmentProducer> shDeviceSupplier = shEquipmentProducerDao.queryShEquipmentProducerList(shEquipmentProducer);
            dataGrid.setRows(shDeviceSupplier);
        }
        return dataGrid;
	}
    
  
    
}